from os import path, system, getcwd, listdir,remove,scandir
import math
import json
import json
import json as js
import sys
import time
import re
import logging
import streamlit.components.v1 as components
import time
import matplotlib.pyplot as plt
#import blacstab2
import demjson
import os
import socket
import yaml
import pandas as pd
from collections import OrderedDict
import streamlit as st
import pyvista as pv
from stpyvista import stpyvista
#import hiplot as hip
import numpy as np
import requests
import random
from dotenv import load_dotenv
import plotly.graph_objects as go
from utils import Cursor
import mpld3
import streamlit.components.v1 as components
from mpld3 import plugins
from streamlit_navigation_bar import st_navbar
from dotenv import load_dotenv
#from BeaverFramework.beavertools import json2yaml, yaml2json
import plotly.express as px
from ruamel.yaml import YAML

#This Application codes from Michael Zhang
load_dotenv()
user_name = os.getenv("USER_NAME")
data_base = os.getenv("BBS_BASE")
run_base = os.getenv("RUN_BASE")
user_log = os.getenv("SYS_LOG")
st.set_page_config(layout="wide")

m = st.markdown("""
<style>
div.stButton > button:first-child {
    background-color: #0099ff;
    color:#ffffff;
}
div.stButton > button:hover {
    background-color: #00ff00;
    color:#ff0000;
    }
</style>""", unsafe_allow_html=True)
# basic dir in .env

new_chords = {}
sections = {}
each_sec = {}
cmp_base = {}
display = True
hostnm=socket.gethostname()
log_path = path.join(getcwd(),'bbs.log')
logger = logging.getLogger("BBS")
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler(log_path)  # file to adding log info
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
#def edit_cell(row, column,df, options):
#    selected_value = st.selectbox('', options, index=options.index(df.at[row, column]))
#    df.at[row, column] = selected_value

def main():
    if hostnm == "mich":
        dir_path=path.join('/home/luban/NAS', user_name, 'BlaCRunData/aero_shape/outputs', 'blade_shape')
    else:
        dir_path = path.join('/home/luban/NAS',user_name, 'BlaCRunData/aero_shape/outputs', 'blade_shape')
    index_file = []
    #page = st_navbar( ['File', 'Airfoils', 'interMethod', 'MakeGeo', 'Lamplan', 'Material', 'BuildBlade','meshBlade','Stiffness','AEP','Stability'])
    page = st_navbar(["SysIters","Hawcstab2", "SimHawc2","Sim","SimFast" ])
    if page == "SysIters":
        ShapeIter,SparCapIter,AirfoilsIter,PrebendIter,WebPositionIter,LamPlan,GroupIter = st.tabs([\
            "ShapeIter","SparCapIter","AirfoilsIter","PrebendIter","WebPositionIter","LamPlan","GroupIter"])
        with ShapeIter:
            col1, col2, col3,col4,col5 = st.columns(5)
            with col1:
                st.markdown(""":blue[请选择一个/组叶片shapes]""")
        with SparCapIter:
            col1, col2, col3,col4,col5 = st.columns(5)
            with col1:
                st.markdown(""":blue[请选择叶片腹板范围]""")
        with AirfoilsIter:
            col1, col2, col3,col4,col5 = st.columns(5)
            with col1:
                st.markdown(""":blue[请选择一组叶片翼型]""")
        with PrebendIter:
            col1, col2, col3,col4,col5 = st.columns(5)
            with col1:
                st.markdown(""":blue[请选择一组叶片预弯]""")
        with WebPositionIter:
            col1, col2, col3,col4,col5 = st.columns(5)
            with col2:
                st.markdown(""":blue[请选择一组叶片web位置]""")
        with LamPlan:
            col1, col2, col3,col4,col5 = st.columns(5)
            with col2:
                st.markdown(""":blue[选择一组铺层文件]""")
        with GroupIter:
            col1, col2, col3,col4,col5 = st.columns(5)
            with col2:
                st.markdown(""":blue[请选择一个或一组叶片变量]""")
    if page == "HawcStab2":
        RunStab2,AITrade,AISmart = st.tabs(["RunStab2","AITrade","AISmart"])
        with RunStab2:
                st.write("please RUN HAWCSTAB2 to make  data for AI")
        with AITrade:
                st.write("please choice trader system variables then AI will find top x for you")
        with AISmart:
                st.write("please choice web position range here for do StaticSim for AI data")
        
    elif page == "SimHawc2":
        t1,t2,t3,t4 = st.columns(4)
        TurbineModels,LoadCase12,LoadCase13,Tuning3D,ControlModel,AITrade,AISmart = st.tabs([\
            "ShapeIter","SparCapIter","AirfoilsIter","PrebendIter","WebPositionIter","GroupIter","AITrade","AISmart"])
        with ShapeIter:
                st.write("please choice shapes here for do StaticSim for AI data")
        with AirfoilsIter:
                st.write("please choice Foils here for do StaticSim for AI data")
        with SparCapIter:
                st.write("please choice Spar cap range here for do StaticSim for AI data")
        with GroupIter:
                st.write("please choice shapes here for do StaticSim for AI data")
        with PrebendIter:
                st.write("please choice shapes here for do StaticSim for AI data")
        with WebPositionIter:
                st.write("please choice web position range here for do StaticSim for AI data")
        with AITrade:
                st.write("please choice web position range here for do StaticSim for AI data")
        with AISmart:
                st.write("please choice web position range here for do StaticSim for AI data")
    elif page == "SimBladed":
        t1,t2,t3,t4 = st.columns(4)
    elif page == "SimFast":
        t1,t2,t3,t4 = st.columns(4)
    else:
        pass
    
if __name__=="__main__":
    css = """
        table
        {
        border-collapse: collapse;
        }
        th
        {
        color: #ffffff;
        background-color: #000000;
        }
        td
        {
        background-color: #cccccc;
        }
        table, th, td
        {
        font-family:Arial, Helvetica, sans-serif;
        border: 1px solid black;
        text-align: right;
        }
    """
    main()
